﻿@model System.Collections.ArrayList
@{
    ViewBag.Title = "Requistion Detail";
    Layout = "~/Views/Shared/_Layout.cshtml";
    BTKERP.Model.RequisitionMaster master = Model[0] as BTKERP.Model.RequisitionMaster;
    List<BTKERP.Model.RequisitionDetail> details = Model[1] as List<BTKERP.Model.RequisitionDetail>;
    List<BTKERP.Model.Product> products = Model[2] as List<BTKERP.Model.Product>;
}
@section AdditionalJS
{

<script type="text/javascript">
    $(function () {
        $("#requisitionDate,#deliveryDate").datepicker();
        $("#fromHouse,#toHouse").addClass("W200").addClass("Margin10");

        var errorMessage = '@ViewData["ErrorMessage"]';
        if (errorMessage.length > 0) {
            alert(errorMessage);
        }
    });

    function submitForm(type) {
        $("#actionType").val(type);
        $("#reqForm").submit();
    }
</script>
}
<form id="reqForm" name="reqForm" action="/Requistion/Add" method="post">
<fieldset>
<legend>Requisition Information</legend>
<input type="hidden" name="actionType" id="actionType" value="" />
<input type="hidden" name="mastid" id="masterid" value="@master.Id.ToString()" />
<table class="editor W800">
    <tbody>
        <tr>
            <td class="right W200">
                Requision From 
            </td>
            <td class="left W300">
                @Html.DropDownList("fromHouse")
               
            </td>
             <td class="right W200">
                Requision To 
            </td>
            <td class="left W300">
                @Html.DropDownList("toHouse")
                
            </td>
        </tr>
        <tr>
            <td class="right">
                Requision Code
            </td>
            <td class="left">
                <input type="text" class="W200 Margin10" id="reqCode" name="reqCode" value="@master.RequisitionCode"/>
            </td>
           <td class="right">
                Delivery Date
            </td>
            <td class="left">
                <input type="text" class="W200 Margin10" id="deliveryDate" name="deliveryDate" value="@master.DeliveryDate.Value.ToString("MM/dd/yyyy")" />
            </td>   
        </tr>
        <tr>
            <td class="right">
                Requision Date
            </td>
            <td class="left">
                <input type="text" id="requisitionDate" name="requisitionDate" class="W200 Margin10" readonly="readonly" value="@master.RequisitionDate.ToString("MM/dd/yyyy")" />
            </td>
            <td class="right">
                Requision By
            </td>
            <td class="left">
                @Html.DropDownList("UserList",ViewData["UserList"] as IEnumerable<SelectListItem>,new { @class="W100 Margin10"})           
            </td>
        </tr>
        <tr>
            <td class="right">
                Fulfilled Date
            </td>
            <td class="left">
                <input type="text" id="fullfilledDate" class="W200 Margin10" disabled="disabled" value="@master.FulfilledDate.ToString("MM/dd/yyyy")" />
            </td>
            <td class="right">
                Fulfilled By
            </td>
            <td class="left">
                <input type="text" class="W200 Margin10" disabled="disabled" value="@BTKERP.MVCWeb.AppCode.SessionHelper.Current.Staff.DisplayName"/>
            </td>
        </tr>   
        <tr>
            <td colspan="4" class="center">
                <input type="button" id="btnSave" class="btn btn-blue" value="Save" onclick=" submitForm(1);"/>
                <input type="button" id="btnSubmit" class="btn btn-green" value="Submit" onclick="submitForm(2)"/>
                <input type="button" value="Cancel" class="btn btn-red" onclick="$('#reqHeadForm')[0].reset();" />
            </td>
        </tr>  
    </tbody>
</table>

</fieldset>
<hr />
<table id="dt" class="display stylized">
    <tr>
        <th>Item Name</th>
        <th>Push\Pack Units</th>
        <th>Current On Hand</th>
        <th>Quantity Req'd</th>
    </tr>
    @foreach (var product in products)
    {
    <tr>
        <td>@product.Name</td>   
        <td>
            <select id="unit|@product.Id.ToString()" name ="unit|@product.Id.ToString()">
                <option value="@product.PackUnitId"> @BTKERP.MVCWeb.AppCode.DataRefHelper.GetUnitName(@product.PackUnitId.ToString())</option>
                <option value="@product.PhysicalUnitId"> @BTKERP.MVCWeb.AppCode.DataRefHelper.GetUnitName(@product.PhysicalUnitId.ToString())</option>
            </select>
        </td>
        <td>
            @BTKERP.MVCWeb.AppCode.DataRefHelper.GetCurrentStock(product.Id, master.FromWarehouseId)
        </td>
        <td>
            <input type="text" class="W200" id="number|@product.Id.ToString()" name="number|@product.Id.ToString()" value="@BTKERP.MVCWeb.AppCode.DataRefHelper.GetRequisitionNumber(product,details,master.Id.ToString())" />
        </td>
    </tr>
    }
</table>
</form>